<!-- /*
 *  mini-SaaS
 *  Application for developing Software as a Service (SaaS) 
 *  Copyright (c) 2011 Anand Sudhakaran, Bryce Holton, Chao Zhang
 *  ASU
 *
 *  This file is part of mini-SaaS.
 *
 *  mini-SaaS is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *  
 *  mini-SaaS is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.

 *  You should have received a copy of the GNU General Public License
 *  along with mini-SaaS; if not, see <http://www.gnu.org/licenses/>. 
 *
 */
  -->


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" session="true"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.util.*, loginbean.*" %>
<html>
	<head>
	<%
	if(session.getAttribute("username")==null || session.getAttribute("username")=="")
	{
			response.sendRedirect("index.jsp");
	}
%>
		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
		<title>Customize a Work Flow</title>
		<script type="text/javascript">
			var counter = 0;
	
			function moreFields(selectobj, var2) 
			{
				counter++;
				var newFields = document.getElementById('readroot').cloneNode(true);
				newFields.id = '';
				newFields.style.display = 'block';
				var newField = newFields.childNodes;
				for (var i = 0; i < newField.length; i++) 
				{
					var theName = newField[i].name
					if (theName)
					{
						newField[i].name = theName + counter;
						newField[i].value = selectobj.selectedIndex +"-"+ var2;
					}
				}
				var insertHere = document.getElementById('writeroot');
				insertHere.parentNode.insertBefore(newFields,insertHere);
			}
	
			window.onload = moreFields;
		</script>		

<link href="twoColElsLtHdr.css" rel="stylesheet" type="text/css" /><!--[if IE]>
<style type="text/css"> 
/* place css fixes for all versions of IE in this conditional comment */
.twoColElsLtHdr #sidebar1 { padding-top: 30px; }
.twoColElsLtHdr #mainContent { zoom: 1; padding-top: 15px; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]-->
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="SpryAssets/SpryMenuBarVertical.css" rel="stylesheet" type="text/css" />
</head>

<body class="twoColElsLtHdr">

<div id="container">
  <div id="header">
    <h1><a href="welcome.jsp"><img src="saas-model.jpg" width="206" height="138" hspace="5" align="left" /></a>Anand, Bryce, Chao's Mini-SaaS</h1>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
  <!-- end #header --></div>
  <div id="sidebar1">
    <ul id="MenuBar1" class="MenuBarVertical">
	  <li><a class="MenuBarItemSubmenu" href="welcome.jsp">Home</a>
      <li><a class="MenuBarItemSubmenu" href="#">Object Menu</a>
        <ul>
          <li><a href="createObject.jsp">Create Custom</a></li>
          <li><a href="display.jsp">Display</a></li>
</ul>
      </li>
      <li><a href="#" class="MenuBarItemSubmenu">WorkFlow Menu</a>
        <ul>
          <li><a href="CreateWorkFlow.jsp">Create New</a></li>
          <li><a href="CustomizeWorkFlow.jsp">Customize</a></li>
        </ul>
      </li>
      <li><a class="MenuBarItemSubmenu" href="#">WebService Menu</a>
        <ul>
          <li><a href="CreateWebService.jsp">Create New</a>          </li>
          <li><a href="displayAvailableWebServices.jsp">Display</a></li>
          <li><a href="searchWebServices.jsp">Search</a></li>
        </ul>
      </li>
      <li><a href="#" class="MenuBarItemSubmenu">GUI</a>
        <ul>
          <li><a href="CustomizeGUI.jsp">Customize</a></li>
        </ul>
      </li>
      <li><a class="MenuBarItemSubmenu" href="Logout.jsp">Log Out</a>
    </ul>
  </div>
  <div id="mainContent">
		<h3>If you attempt to edit an predefined system work flow a new one will be created for you with your name appended to the front.</h3>
		<p>
		Once you have selected a work flow, you can test it by selecting the link below it.
		</p>		
<form action="workflowcontroller" method=post>
			Select a Work Flow to Customize: 
			<% out.println( WorkFlow.getAllWorkFlows( Integer.parseInt( session.getAttribute("tenantid").toString() ) ) ); %>
			<input type="hidden" name="viewcmd" value="B" />
			<input type="submit" value="Retrieve Work Flow" />
		</form>
		<%
out.println("<a href=\"http://xlnm.com:8080/SaaSClient/Result2.jsp?tenantid="+session.getAttribute("tenantid")+"&workflowname="+session.getAttribute("workFlowName")+"\">"+session.getAttribute("workFlowName")+"</a>");
		//
			Vector<String> serviceNames = (Vector<String>)session.getValue("serviceNames");
			Vector<Integer> serviceOrder = (Vector<Integer>)session.getValue("serviceOrder");
			if(serviceNames != null && serviceNames.size() != 0)
			{
		%>

				<table border=1>
					<tr>
						<th>Web Service Name</th>
						<th>Current Operation Order</th>
						<th>New Operation Order</th>
						<th>Delete Web Service</th>
					</tr>
		<%
					for(int i = 0; i < serviceNames.size(); i ++)
					{
						out.println("<tr>");
						out.println("<td>"+ serviceNames.elementAt(i) +"</td>");
						out.println("<td>"+ serviceOrder.elementAt(i) +"</td>");
						out.println("<td>");
						out.println("<SELECT name='svcOrder' onChange=\"moreFields(this,'"+ serviceNames.elementAt(i) +"')\">");
						int highestSvcNum = WorkFlow.getMaxSvcNum(Integer.parseInt( session.getAttribute("tenantid").toString()), (String)session.getAttribute("workFlowName"));
						out.println("<option></option>");
						for(int j = 1; j < highestSvcNum + 1 ; j ++)
						{
							out.println("<option>"+ j + "</option>");
						}
						out.println("</SELECT>");
						out.println("</td>");
						out.println("<td><form action=\"workflowcontroller\" method=post>");
						out.println("<input type=\"hidden\" name=\"viewcmd\" value=\"D\" />");
						out.println("<input type=\"hidden\" name=\"del\" value=\""+ serviceOrder.elementAt(i) +"\" />");
						out.println("<input type=\"submit\" value=\"Delete\" />");
						out.println("</form></td>");
						out.println("</tr>");
					}
		%>
				</table>
				<div id="readroot" style="display: none">
					<input type="hidden" name="test" value="" />
				</div>
				<form action="workflowcontroller" method=post>
					<input type="hidden" name="viewcmd" value="C" />
					<span id="writeroot"></span>
					<input type="submit" value="Submit New Work Flow" />
				</form>
				<form action="workflowcontroller" method=post>
					<input type="hidden" name="viewcmd" value="E" />
					Select a new Web Service: 
					<% out.println( WorkFlow.getAllWebServices( Integer.parseInt( session.getAttribute("tenantid").toString() ) ) ); %>
					<input type="submit" value="Add This New Service to the Work Flow" />
				</form>				
		<%				
			}
		%>	
  <!-- end #mainContent --></div>
	<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
   <div id="footer">
    <p>&nbsp;</p>
  <!-- end #footer --></div>
<!-- end #container --></div>
<script type="text/javascript">
<!--
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
//-->
</script>					 
	</body>
</html>
